package ve.usb.crm;

import java.io.File;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DownloadAction;
import org.hibernate.Session;
import ve.usb.cohesion.runtime.HibernateUtil;
import ve.usb.crm.hibernate.Documento;

public class AccionesDescarga extends DownloadAction{

    protected StreamInfo getStreamInfo(ActionMapping mapping,
                                       ActionForm form,
                                       HttpServletRequest request,
                                       HttpServletResponse response)
            throws Exception {

        Long idDocumento = new Long(request.getParameter("idDocumento"));
        Session s = HibernateUtil.getCurrentSession();
        Documento documento = (Documento)s.load(Documento.class, idDocumento);
        String contentType = documento.getContentType();
        File file          = new File(documento.getEnlace());

        return new FileStreamInfo(contentType, file);

    }

}